/***********************************图片上传预览*********************************************/
//图片上传预览    IE是用了滤镜。
//IE9以下时，文件选择框不能隐藏
//id1必须给固定宽度和高度
//注意：id2所对应的img一定要加上 {filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image);}样式
function previewImage(id1,id2,file,cb)
{
  var div = (typeof id1 === "string")?document.getElementById(id1):id1;
  if(id2 == ""){
  	id2 = "id2"+getTimeString();
  }
  //id1的最大宽度和高度	
  var MAXWIDTH  = div.offsetWidth-2; 
  var MAXHEIGHT = div.offsetHeight-2;
  if (file.files && file.files[0])
  {
      div.innerHTML ='<img id='+id2+'>';
      var img = document.getElementById(id2);
      img.onload = function(){
        var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
        img.width  =  rect.width;
        img.height =  rect.height;
        img.style.marginTop = rect.top+'px';
        img.style.marginLeft = rect.left+'px';
      }
      var reader = new FileReader();
      var src = "";
      reader.onload = function(evt){img.src = evt.target.result;src = evt.target.result;
	      if(cb){
		 	cb(src);
		  }
      }
      reader.readAsDataURL(file.files[0]);
     
  }
  else //兼容IE
  {
    var sFilter='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
    file.select();
	//取消选中文件上传按钮
	file.blur();
	file.parentNode.focus();
//	document.getElementsByTagName("input")[0].focus();
	//window.parent.document.body.focus();
//    var src = document.selection.createRange().text;
    var src = file.value;
    div.innerHTML = '<img id='+id2+'>';
    var img = document.getElementById(id2);
    img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
    var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
	div.innerHTML = "<div id="+id2+" style='width:"+rect.width+"px;height:"+rect.height+"px;margin-top:"+rect.top+"px;;margin-left:"+rect.left+"px;"+sFilter+src+"\"'></div>";
	if(cb){
		cb(src);
	}
  }
};
//图片等比例缩放适应预览框的参数初始化
function clacImgZoomParam( maxWidth, maxHeight, width, height ){
    var param = {top:0, left:0, width:width, height:height};
    if( width>maxWidth || height>maxHeight )
    {
        rateWidth = width / maxWidth;
        rateHeight = height / maxHeight;
         
        if( rateWidth > rateHeight )
        {
            param.width =  maxWidth;
            param.height = Math.round(height / rateWidth);
        }else
        {
            param.width = Math.round(width / rateHeight);
            param.height = maxHeight;
        }
    }
    param.left = Math.round((maxWidth - param.width) / 2);
    param.top = Math.round((maxHeight - param.height) / 2);
    return param;
};

/*
 * 根据图片路径，获取
 * */
//获取图片尺寸，网络图片
	function getMulImgSizes(src,cb){
		var parm = {},w=0,h=0;
		var max_del = document.getElementById("$max_del");
		if(max_del){
			document.body.removeChild(max_del);
		}
		var div = document.createElement("div");
		var time = new Date().getTime();
		div.id = "$max_del"+time;
		div.style.display = "none";
		document.body.appendChild(div);
		var tempImg = document.createElement("img");
		tempImg.src = src;
		div.appendChild(tempImg);
		if(getBrowerType() =="IE8"){
			var img = new Image();
			img.onload = function(){
				w = img.width;
				h = img.height;
				if(cb){
					cb(w,h);
				}
				if(document.getElementById("$max_del"+time)){
					document.body.removeChild(document.getElementById("$max_del"+time));
				}
			}
			img.src = src;
			return parm;
		}else{
			tempImg.onload = function(){
				
				if(tempImg.naturalWidth){
					w = tempImg.naturalWidth;
					h = tempImg.naturalHeight;
					if(cb){
						cb(w,h);
					}
					parm.width = w;
					parm.height = h;
					if(document.getElementById("$max_del"+time)){
						document.body.removeChild(document.getElementById("$max_del"+time));
					}
					return parm;
				}else{
					var img = new Image();
					img.onload = function(){
						w = img.width;
						h = img.height;
						if(cb){
							cb(w,h);
						}
						if(document.getElementById("$max_del"+time)){
							document.body.removeChild(document.getElementById("$max_del"+time));
						}
					}
					img.src = src;
					return parm;
				}
			}	
		}
	}
	
function getImgSizes(src,cb){
		var w=0,h=0;
		var img = new Image();
		if(typeof img.naturalWidth == "undefined"){//不支持现代浏览器的naturalWidth属性
			if(!!window.ActiveXObject){//IE8/9等不支持onload方法的浏览器
				img.onreadystatechange = function(){
					if(this.readyState == "complete"){
						w = img.width;
						h = img.height;
						if(cb){
							cb(w,h);
						}
						return {
							"width":w,
							"height":h
						}
					}
				}
			}else{
				img.onload = function(){
					w = img.width;
					h = img.height;
					if(cb){
						cb(w,h);
					}
					return {
						"width":w,
						"height":h
					}
				}
			}
			img.src = src;
		}else{//支持naturalWidth属性的现代浏览器
			img.src = src;
			w = img.naturalWidth;
			h = img.naturalHeight;
			if(cb){
				cb(w,h);
			}
			return {
				"width":w,
				"height":h
			}
		}
	}
/**
 * 获取本地上传图片的真实大小 
 * @param img为存在的dom对象  
 * @param callback 回调函数
 * @returns {widht:宽度大小,height:高度大小}
 */ 
function getImgNaturalDimensions(img, callback) {
	var whJson={};
	var nWidth, nHeight 
	 //alert(img)
	 if(typeof img.naturalWidth == "undefined"){ // IE6/7/8/9
	 	var src = img.src
		if(!src){
		 var type = getBrowerType();
		 if(type == "IE8" || type == "IE9"){
			 //获取filter的样式信息
			 //var filter = getStyle(img,"filter");
			var filter = img.style.filter; 
			var srcTemp1 = filter.split("src=\"");
			var srcTemp2 = srcTemp1[1];
			var srcTemp3 = srcTemp2.split("\"");
			src = srcTemp3[0];
		 }
	 	}
		var newImg = new Image();
   	newImg.src = img.src;
   	if(!!window.ActiveXObject){
   		newImg.onreadystatechange = function(){
   			if(this.readyState == "complete"){
   				nWidth = newImg.width;
   				nHeight = newImg.height
   				if(callback){
						callback(nWidth,nHeight)
					}
					whJson.width = nWidth;
					whJson.height = nHeight;
					return whJson;
   			}
   		}
   	}else{
   		newImg.onload = function(){
 				nWidth = newImg.width;
 				nHeight = newImg.height
 				if(callback){
					callback(nWidth,nHeight)
				}
 				whJson.width = nWidth;
				whJson.height = nHeight;
				return whJson;
   		}
   	}
	 	newImg.src = src ;
	 }else{ // 现代浏览器 
	   	nWidth = img.naturalWidth 
	   	nHeight = img.naturalHeight
			if(callback){
				callback(nWidth,nHeight)
			}
			whJson.width = nWidth;
			whJson.height = nHeight;
			return whJson;
	 };
	 
}

/**
 * 预览照片
 * @param dom 照片放置的容器，为dom是js的dom对象
 * @param src 照片获取的本地地址
 * @returns {Boolean}
 */
function previewPhoto(dom,src){
    if(!src){ 
        return
    }
    if(window.navigator.userAgent.indexOf("MSIE") >= -1) {
        if(dom) {
            try{
                dom.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = src;
            }catch(ex){
            	alert("文件路径非法，请重新选择！") ;
            	return false;
            }
        }else{ 
        	dom.innerHTML="<img src='"+picsrc+"' />";
        }
    }
}

/**
 * 获取图片的真实大小
 * @param src 为本机图片路径，不能为带“http://”的图片
 * @returns {width:w,height:h}
 */
function checkPhoto(src){
	var picpreview = document.createElement("div");
	picpreview.ID = "preview_$div";
  picpreview.style.width = "10px";
  picpreview.style.height = "10px";
  picpreview.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
  picpreview.style.visibility = "hidden";
  document.body.appendChild(picpreview);

  var w,h;
  previewPhoto(picpreview,src);
  var imgObj = new Image();
  imgObj.src = src;
  var width = imgObj.width;
  var height = imgObj.height;
  //获取正确的图片尺寸大小，兼容ie6、7、8
 
  try{
    if((typeof width=="undefined" || width==0) && (typeof height=="undefined" || height==0)){
	    if(picpreview && picpreview.filters && picpreview.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src) {
		    var tempDiv=document.createElement("div");
		    picpreview.appendChild(tempDiv);
		    tempDiv.style.width="10px";
		    tempDiv.style.height="10px";
		    tempDiv.style.diplay="none";
		    tempDiv.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image);";
		    tempDiv.ID="previewTemp";
		    var url=picpreview.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src;
		    tempDiv.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src=url;
		    w=tempDiv.offsetWidth;
		    h=tempDiv.offsetHeight;
		    picpreview.removeChild(tempDiv);
	    }
    }
  }catch(e){
  	
  }
  if(src.toLowerCase().indexOf("http://") > - 1){
  	alert("必须提供本机硬盘上的图片上传！");
  	return false;
  }
//    alert("照片宽："+w+"像素 \n照片高："+h+"像素");
  document.body.removeChild(picpreview)
  return {width:w,height:h};
}


/********************************************************************************/
//初始化图片margin-left和margin-top
function initImgParm(maxW,maxH,width,height){
	var l=0,t=0,w=width,h=height;
	if(width >= maxW && height >= maxH){//图片的宽高大于最大宽高
		w = width;
		h = height;
	}else if(width >= maxW && height < maxH){//图片的宽度大于最大宽度，高度小于最大高度
		t = (maxH - height) / 2;
	}else if(width < maxW && height >= maxH){ //图片的宽度小于最大宽度，高度大于最大高度
		l = (maxW - width ) / 2;
	}else if(width < maxW && height < maxH){//图片比最大的宽度和高度都小
		t = (maxH - height) / 2;
		l = (maxW - width ) / 2;
	};
	var whltjson = {}
	whltjson.left = l;
	whltjson.top = t;
	whltjson.width = w;
	whltjson.height = h;
	return whltjson;
};
/*
 * 图片自适应最大宽高 
 * 
 * 最大宽度，最大高度，实际宽度，实际高度 
 * */
function adapterImgSize(maxW,maxH,width,height){
	var parm = {},l=0,t=0,w=0,h=0;
	if(width > maxW && height > maxH){//图片宽高大于最大宽高
		var perMax = maxW / maxH ;
		var per = width / height ;
		if(perMax >= per){ //以宽为基准
			w = maxH * width / height ;
			h = maxH;
			l = ( maxW - w ) / 2 ;
		}else {
			w = maxW;
			h = maxW * height / width;
			t = ( maxH - h ) / 2 ;
		}
	}else if(width > maxW && height < maxH){
		w = maxW;
		h = maxW * height / width;
		t = ( maxH - h ) / 2 ;
	}else if(width < maxW && height > maxH){
		w = maxH * width / height ;
		h = maxH;
		l = ( maxW - w ) / 2 ;
	}else if(width <= maxW && height <= height){//图片的宽高小于最大宽高
		w = width;
		h = height;
		l = ( maxW - width ) / 2;
		t = ( maxH - height ) / 2;
	}
	parm.width = w;
	parm.height = h;
	parm.left = l;
	parm.top = t;
	return parm;
};

//id1在id2中居中显示，id1和id2已经添加position才起效果
function $center(id1,id2){
	var w1 = $(id1).width();
	var h1 = $(id1).height();
	var w2 = $(id2).width();
	var h2 = $(id2).height();
	var l = (w2 - w1) / 2;
	var t = (h2 - h1) / 2;
	$(id1).css({"top":t,"left":l});
};

//获取当天时间
function getYMD() {
	var toDate = new Date();
	var y = toDate.getFullYear();
	var m = toDate.getMonth() + 1;
	var d = toDate.getDate();
	var value = y + "-" + m + "-" + d;
	return value;
};

//判断是不是编辑证件,是为true，否为false
function isVoucher(tarId){
	var mark = false;
	var idArr = tarId.split("_");
	//如果是证件
	if(idArr[0] == "voucher"){
		mark = true;
	}
	return mark;
};

/*
 * 
 * 获取浏览器版本
 * 
 * */
function getBrowerType(){
	var type ="";
	var userMananer = (navigator.userAgent).toUpperCase();
	if(userMananer.indexOf("MSIE 6") > -1 ){
		type = "IE6";
	}else if(userMananer.indexOf("MSIE 7") > -1 ){
		type = "IE7";
	}else if(userMananer.indexOf("MSIE 8") > -1 ){
		type = "IE8";
	}else if(userMananer.indexOf("MSIE 9") > -1 ){
		type = "IE9";
	}else if(userMananer.indexOf("MSIE 10") > -1 ){
		type = "IE10";
	}else if(userMananer.indexOf("TRIDENT") > -1 && userMananer.indexOf("RV") >-1 ){
		type = "IE11";
	}else if(userMananer.indexOf("CHROME") > -1 ){
		type = "Chrome";
	}else if(userMananer.indexOf("FIREFOX") > -1 ){
		type = "Firefox";
	}else if(userMananer.indexOf("OPERA") > -1 ){
		type = "Opera";
	}else if(userMananer.indexOf("SAFARI") > -1 ){
		type = "Safari";
	}else{
		type = "other";
	}
	return type;
}

/*
 * 处理ajax方式访问，当session过期时导致的不跳转登录页问题
 * 
 */
$.ajaxSetup({
    contentType:"application/x-www-form-urlencoded;charset=utf-8",
    complete:function(XMLHttpRequest,textStatus){
          //通过XMLHttpRequest取得响应头，sessionstatus           
          var sessionstatus=XMLHttpRequest.getResponseHeader("sessionstatus"); 
          var url = XMLHttpRequest.getResponseHeader("url");
          if(sessionstatus=="timeout"){
              //这里跳转的登录页面
        	  alert("页面过期，请重新登录");
        	  window.top.location.href=url;
       }
    }
});



/***************************************************************************************************/

	

//图片验证id为file input的id,也可为该dom对象
/**
* 	本地上传图片的验证 
*	id为file 文本框的id或该file文本框对应的dom对象
* 	json{width:0,height:0,fileSize:0,compare:-1,callback:function(){}}
* 	width为0，则不对width比较，
* 	height为0,则不对height比较.
* 	compare为1，宽高大于width,height。
* 	compare为0,宽高等于width,height。
* 	compare为-1,宽高小于width,height。
* 	fileSize为0，则不对fileSize比较
* 	callback回调函数，function(mark){mark为true时图片验证正确，false时图片验证不正确}
*/
function imgValid(id,json){
	var dom = typeof id==="string"?document.getElementById(id):id;
	var opts = {width:0,height:0,compare:-1,fileSize:0,callback:function(){}};
	opts = mix(opts,json);
	var _isimg = isImg(id);
	var _isDimenSion = true;
	var _isSize = true;
	
	//判断图片大小
	if(opts.fileSize != 0){
		var num = parseInt(opts.fileSize);
		var txt = opts.fileSize.replace(num,"").toUpperCase();
		var fileSize = 0;
		if(txt == "M" || txt =="MB"){
			fileSize = num * 1024 * 1024;
		}else if(txt == "KB") {
			fileSize = num * 1024 ;
		}else{
			fileSize = num;
		}
		var _size = getImgFileSize(id);
		if(_size){
			if(_size > fileSize){
				/*alert("图片太大了，图片最大为"+opts.fileSize);*/
				if($.isFunction(MaxAlert)){
					MaxAlert("图片太大了，图片最大为"+opts.fileSize);
				}else{
					alert("图片太大了，图片最大为"+opts.fileSize);
				}
				_isSize = false;
			}
		}else{
			_isSize = false;
		}
	}
	
	//判断图片尺寸
	if(opts.width != 0 || opts.height != 0){
		getImgDimension(id,function(w,h){
			var wmark = true;
			var hmark = true;
			//判断宽度
			if(opts.width){
				if(opts.compare < 0){//
					if(w > opts.width){
						wmark = false;
					}
				}else if(opts.compare > 0){
					if( w < opts.width){
						wmark = false;
					}
				}else{
					if( w != opts.width){
						wmark = false;
					}
				}
			}
			//判断高度
			if(opts.height){
				if(opts.compare < 0 ){
					if(h > opts.height){
						hmark = false;
					}
				}else if(opts.compare > 0){
					if(h < opts.height){
						hmark = false;
					}
				}else{
					if(h != opts.height){
						hmark = false;
					}
				}
			}
			
			if(wmark && hmark){
				_isDimenSion = true;
			}else{
				var op = "小于";
				if(opts.compare == 1){
					op = "大于"
				}else if(opts.compare == 0 ){
					op ="等于";
				};
				/*alert("图片尺寸"+op+" "+opts.width+" * "+opts.height+",请重新选择！")*/
				if($.isFunction(MaxAlert)){
					MaxAlert("图片尺寸"+op+" "+opts.width+" * "+opts.height+",请重新选择！");
				}else{
					alert("图片尺寸"+op+" "+opts.width+" * "+opts.height+",请重新选择！");
				}
				_isDimenSion = false;
			}
			var valid = false;
			if(_isimg && _isDimenSion && _isSize){
				valid = true ;
			};
			//清空file 文本框的值
			if(!valid){
				dom.value = "";
			};
			//回调函数
			if(opts.callback){
				opts.callback(valid);
			}
		});
	}else{
		var valid = false;
		if(_isimg && _isSize){
			valid = true;
		};
		//清空file 文本框的值
		if(!valid){
			dom.value = "";
		};
		//回调函数
		if(opts.callback){
			opts.callback(valid);
		}
	};
};
//对象混入
function mix(target,source){
	var arr = [];
	var args = arr.slice.call(arguments);
	var i = 1;
	if(args.length==1){
		return target;
	};
	while((source = args[i++])){
		for(var key in source){
			if(source.hasOwnProperty(key)){
				var obj = target[key];
				if(typeof obj == "object" && obj.constructor != Array ){//不是数组，则是json
					for (var key1 in source[key]) {
						if(source[key].hasOwnProperty(key1)){
							obj[key1] = source[key][key1];
						}
					}
				}else{
					(function(str){
						target[str] = source[str];
					})(key);
				}
			}
		};
	}
	return target;
};

/**
*	判断file文本框的文件是否是图片 
*	id可为file文本框的id,也可是该file文本框的dom对象
*/
function isImg(id){
	var dom = typeof id==="string"?document.getElementById(id):id;
	var filepath = dom.value;
	if(filepath){
	//	var txt = filepath.substring(filepath.lastIndexOf("."),filepath.length).toUpperCase();
		var txtArr = filepath.split(".");
		var txt = txtArr[txtArr.length-1].toUpperCase();
		if(txt != "PNG" && txt !="JPEG" && txt !="JPG" &&txt != "BMP" && txt != "GIF"){
			/*alert("图片限于bmp,png,gif,jpeg,jpg格式");*/
			if($.isFunction(MaxAlert)){
				MaxAlert("图片限于bmp,png,gif,jpeg,jpg格式");
			}else{
				alert("图片限于bmp,png,gif,jpeg,jpg格式");
			}
			return false;
		}
		return true;				
	}else{
		return false;
	}
};

/*
* 通过file文本框，获取上传图片的尺寸
* id是file文本框的id或该file文本框对应的dom对象
* cb为回调函数，如果有回调函数，回调函数会在300ms后执行
* */
function getImgDimension(id,cb){
	var file = typeof id==="string"?document.getElementById(id):id;
	var type = getBrowerType();
		if (file.files && file.files[0]){//IE10，IE11，FireFox，chrome
	    var img = document.createElement("img");
	    var reader = new FileReader();
	    reader.onload = function(evt){
	    	img.src = evt.target.result;
	    	if(cb){
	    		setTimeout(function(){
	    			var wh = getImgNaturalDimensions(img);
	    			cb(wh.width,wh.height);
	    		},100);
	    	}
	 	}
		reader.readAsDataURL(file.files[0]);
	}else if(type=="IE8" || type =="IE9") {//兼容IE89
	    var sFilter='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
	    file.select();
		//取消选中文件上传按钮
		file.blur();
		file.parentNode.focus();
	    var src = file.value;
		var div = document.createElement("div");
	    div.innerHTML = "<div style='"+sFilter+src+"'></div>";
	    document.body.appendChild(div);
	    if(cb){
	    	setTimeout(function(){
	    		var img = div.firstChild;
	    		var wh = getImgNaturalDimensions(img);
	    		cb(wh.width,wh.height);
	    		document.body.removeChild(div);
	    	},100);
	    }else{
	    	 document.body.removeChild(div);
	    }
	};
};
/*
*	获取图片文件的大小（kb）
* */
function getImgFileSize(id){
	var dom = typeof id==="string"?document.getElementById(id):id;
	var type = getBrowerType();
	var file = "";
	var fileSize = 0;
	if(type == "IE8"){
		file = dom;
		if(file){
			var filePath = file.value;
			var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
			var file = fileSystem.GetFile (filePath);
			fileSize = file.Size; 
		}
	}else if(type == "IE9"){
		/* 
			IE9 获取文件大小
		*/
		//alert("可恶的IE9，无法获取文件大小，请升级或换用其他浏览器");
		fileSize = 1;
	}else{
		file = dom.files[0];
		if(file){
			fileSize = file.size;
		}
	}
	return fileSize;
};

//按回车时光标切换到Id密码框
function enterNext(id,e){
	var ev = e.event || window.event || window.which;
	var type = getBrowerType();
	if(ev.keyCode == 13){
		$("#"+id).focus();
	}
};
//按回车时模拟点击Id所在的dom对象
function enterLogin(id,e){
	var ev = e.event || window.event || window.which;
	if(ev.keyCode == 13){
		$("#"+id).trigger("click");
	}
};

//阻止冒泡行为
function stopBubbing(e){
	if(event.stopPropagation){
		e.stopPropagation();
	}else{
		e.cancelBubble = true;	//iE678
	}
};

function stopPropa(e){
	if(event.stopPropagation){
		e.stopPropagation();
	}else{
		e.cancelBubble = true;	//iE678
	}
};

//阻止浏览器默认事件
function stopDefault(e){
	if(event.preventDefault){
		return e.preventDefault();
	}else{
		e.returnValue = false;	//iE678
	}
};
/*************************************************************************************************************/
//阻止冒泡行为
function stopPgation(e){
	if(event.stopPropagation){
		e.stopPropagation();
	}else{
		e.cancelBubble = true;	//iE678
	}
};

//IE9以下替换input[type='text']的placeholder的值，并写入文本框内
function showPlaceholder(){
	var btype = getBrowerType();
	if(btype == "IE8" || btype == "IE9" || btype == "IE7"){
		var inputs = $("input[type='text']");
		//alert(inputs.length)
		for(var i=0,len = inputs.length;i<len;i++){
			(function(n){
				var tar = inputs.eq(n);
				var text = tar.attr("placeholder");
				if(text){
					inputs.eq(n).val(text);
				}
			})(i);
		};
	};
};
//IE9以下绑定事件，input[type='text']获取焦点清空内容，拾取焦点时，判断placeholder与内容
//input[type='password']的id为password，并且有兄弟元素input[type='text'],id也为password
function inputsEvent(){
	var btype = getBrowerType();
	if(btype == "IE8" || btype == "IE9" || btype == "IE7"){
		$("input[type='text']").on("focus",function(){
			if($(this).val() == $(this).attr("placeholder")){
				$(this).val("");
			}
		}).on("blur",function(){
			if(!$(this).val()){
				$(this).val($(this).attr("placeholder"));
			}
		});
	}
};
//IE89下搜索#searchValue的变化
function searchIE89(){
	var btype = getBrowerType();
	if(btype == "IE8" || btype == "IE9"){
		var text = $.trim($("#searchValue").val());
		var placeholder = $.trim($("#searchValue").attr("placeholder"));
		if(text == placeholder){
			$("#searchValue").val("");
		}
	}
};
//IE89下重置时#searchValue的变化
function resetIE89(){
	var btype = getBrowerType();
	if(btype == "IE8" || btype == "IE9"){
		var placeholder = $.trim($("#searchValue").attr("placeholder"));
		$("#searchValue").val(placeholder);
	}else{
		$("#searchValue").val("");
	}
};

//获取dom对象距离浏览器顶部的距离
function getTop(obj){
	var ctop =0;
	while(obj){
		ctop += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return ctop;
}
//获取dom对象距离浏览器左边的距离
function getLeft(obj){
	var cleft =0;
	while(obj){
		cleft += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return cleft;
};

//主框架新增tab页签
function addTabs(tit,url){
	var index = top.hasOpened(tit,top.openArr);
	if(index == -1){
		top.openArr.push({
			title: tit,
			url: url,
			width: tit.length*12 + top.PADDING_WIDTH
		})
		top.opIframe(top.tabIndex,url,tit);
		top.tabIndex++;
	}else{
		top.openTabPanl(index);
	}
	top.menuAddActive(tit);
	return;
	$("body",top.window.document).find("#mainLayFrame").attr("src",url);
}



function getTimeString(){
	return new Date().getTime();
};

/***********************************提示*******************************************/
//加载显示
/*	
 *  jzts();调用显示加载进度
 *  hangge();清除显示加载进度
 *  可自己更换显示的图片，改变图片后，需要设置imgbox.style.width为图片的宽，imgbox.style.height为图片的高度
 *  width和height为图片的宽高
 * */
/*(function(win){
	var Ts = {
		width:40,
		height:40,
	//	http:"http://www.zgwtl.com:8081/",
		src:"../images/loadingi.gif",
		src:"images/loading.gif",
		tempSrc:"",
	//	jztsClass:"position: fixed;left: 0px;top: 0px;background-color:rgba(1,1,1,.3);filter:Alpha(Opacity=30);width: 100%;height: 100%;z-index:9999999;",
		jzts:function(){
			Ts.tempSrc = Ts.src;
			var tsDom = window.top.document.getElementById("jzts");
			if(tsDom){
				window.top.document.body.removeChild(tsDom);
			}else{
				tsDom = document.createElement("div");
				tsDom.id = "jzts";
				tsDom.className = "jzts";
			//	tsDom.style = Ts.jztsClass;
				var imgbox = document.createElement("div");
				imgbox.style.width = Ts.width +"px";
				imgbox.style.height = Ts.height +"px";
				if(basePath){
					Ts.src = basePath+Ts.src;
				}else{
					Ts.src = "http://www.zgwtl.com:8081/"+Ts.src;
				}
				var imgSrc = Ts.http+Ts.src;
				var imgSrc = Ts.src;
				imgbox.innerHTML = "<img src='"+imgSrc+"' width="+Ts.width+" height="+Ts.height+"/>";
				tsDom.appendChild(imgbox);
				window.top.document.body.appendChild(tsDom);
				Ts._center(imgbox);
			}
		},
		_center:function(dom){
			var w = window.top.document.innerWidth || window.top.document.documentElement.clientWidth;
			var h = window.top.document.innerHeight || window.top.document.documentElement.clientHeight;
			//console.log(w)
			var dw = dom.offsetWidth;
			var dh = dom.offsetHeight;
			var l = ( w - dw ) / 2 ;
			var t = ( h - dh ) / 2 ;
			dom.style.marginLeft = l+"px";
			dom.style.marginTop = t+"px";
		},
		hangge:function(){
			var jzts = window.top.document.getElementById("jzts"); 
			if(jzts){
				window.top.document.body.removeChild(jzts);
			}
			Ts.src = Ts.tempSrc;
		}
	};
	win.jzts = Ts.jzts;
	win.hangge = Ts.hangge;
})(window);*/
/***********************************主框架加载等待遮罩*******************************************/
/*
 * 借助MaxDialog.js插件封装加载等待遮罩
 * */
function jzts(){
	if(parent.window == self.window){//在顶层窗口
		if(parent.window.wating){
			return;
		}
		parent.window.wating = parent.window.maxWating();
	}else{//非顶层窗口
		if(parent.window.wating){
			return;
		}
		parent.window.wating = parent.window.maxWating();
	}
}
//移出加载等待遮罩
function hangge(){
	if(parent.window == self.window){//在顶层窗口
		if(parent.window.wating){
			parent.window.wating.close();
			parent.window.wating = "";
		}
	}else{//非顶层窗口
		if(parent.window.wating){
			parent.window.wating.close();
			parent.window.wating = "";
		}
	}
}
/***********************************局部加载等待*******************************************/
//局部加载等待遮罩
/*
 * id：局部加载区域的id，必须传递。
 * 
 * */
function partJzts(id){
	if($("#partC"+id).length>0){
		return;
	}
	var obj = $("#"+id) || $("body");
	var zIndex = 0;
	if(obj.css("position") == "static"){
		obj.css("position","relative");
		obj.attr("position","static");
	}else{
		zIndex = obj.css("z-index");
	}
	var w = obj.outerWidth();
	var h = obj.outerHeight();
	
	var partCoverImg = "";
	var imgsrc = ""
	
	var $imgBox = $("<div class='partImgBox'><img class='partCoverImg' src='"+partCoverImg+"' width='100%' height='100%' /><img class='watingImg' src='"+imgsrc+"' width='40' height='40' /></div>");
	
	$imgBox.attr({
		"id":"partC"+id
	})
	
	$imgBox.css({
		"position":"absolute",
		"top":0,
		"left":0,
		"width":w,
		"height":h,
		"overflow":"hidden"
	});
	$imgBox.find(".partCoverImg").css({
		"position":"absolute",
		"top":0,
		"left":0,
		"z-index":zIndex+1
	});
	$imgBox.find(".watingImg").css({
		"position":"absolute",
		"top":((h - 40) / 2)<0?0:((h - 40) / 2) ,
		"left":((w - 40) / 2)<0?0:((w - 40) / 2),
		"z-index":zIndex+2
		
	});
	obj.append($imgBox);
}

//局部遮罩移出
/*
 * id为调用partJzts的id，可传可不传；
 * */
function partHangge(id){
	var obj = "";
	if(id){
		obj = $("#partC"+id);
		if($("#"+id).attr("position")){
			$("#"+id).css("position",$("#"+id).attr("position"));
		}
	}else{
		obj = $(".partImgBox");
	}
	obj.remove();
}

/***********************************checkbox 和 radio 表单选中后失去焦点*******************************************/
$(function(){
	$("body").on("click","input[type='checkbox'],input[type='radio'],input[type='file']",function(){
		$(this).blur();
	})
});

/***********************************button 和 a 标签点击或选中后失去焦点*******************************************/
$(function(){
	$("body").on("click","button,a,.btn",function(){
		$(this).blur();
	})
});

/***********************************自定义字体图标按钮禁止事件冒泡*******************************************/
$(function(){
	$("button.btn-img").on("click",function(e){
		var ev = e || window.event || e.which || window.which;
		$(this).blur();
		ev.stopPropagation();
	});
	
	$("table button.btn").on("click",function(e){
		var ev = e || window.event || e.which || window.which;
		$(this).blur();
		ev.stopPropagation();
	});
	
	$("table tr td input").on("click",function(e){
		if( !$(this).is($("input[type='checkbox']"))){
			var ev = e || window.event || e.which || window.which;
			// ev.stopPropagation();
		}
	});
	
});

//置顶
function goTop(){
	$("body").animate({"scrollTop":0});
};

//添加数组IndexOf方法，可用$.inArray(val,array,firstIndex)代替
if (!Array.prototype.indexOf){
  Array.prototype.indexOf = function(elt /*, from*/){
    var len = this.length >>> 0;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++){
      if (from in this && this[from] === elt)
        return from;
    }
    return -1;
  };
};

//获取字符长度，中午占2个字符
function getLength(str){
	var realLength = 0;
	var charCode = "";
	for(var i=0;i<str.length;i++){
		charCode = str.charCodeAt(i);
		if(charCode >=0 && charCode<=128){
			realLength += 1;
		}else{
			realLength += 2;
		}
	}
	return realLength;
}

//获取http:192.168.1.240:8081/wtlShopWeb/
function getHostUrl(){
	var pathname = window.location.pathname.split("\/");
	var urlPath = window.location.protocol +"//"+ window.location.host +"/"+pathname[1]+"/";
	return urlPath;
}


//异步加载js，异步操作
function loadScript(url, callback){
	var script = document.createElement ("script");
	script.type = "text/javascript";
	if (script.readyState){ //IE
		script.onreadystatechange = function(){
      if (script.readyState == "loaded" || script.readyState == "complete"){
      	script.onreadystatechange = null;
      	callback();
      }
		};
	}	else {//Others          
  	script.onload = function(){
  		callback();
  	};
  }
    script.src = url;
    document.getElementsByTagName("head")[0].appendChild(script);
};

//图片自适应容器
function imgInit(jdom){
	var imgs;
	if(jdom){
		imgs = $(jdom).find("img");
	}else{
		imgs =$("img");
	}
	var i = 0;
	imgs.each(function(n){
		var src = $(this).attr("src");
		if(src){
			obj = $(this);
			var maxW = $(this).parent().innerWidth();
			var maxH = $(this).parent().innerHeight();
			var width = height = 0;
			var imgDom = new Image();
			if(!!window.ActiveXObject){
				imgDom.onreadystatechange = function(){
					if(this.readyState == "complete"){
						width = imgDom.width;
						height = imgDom.height;
						//初始化图片显示的参数
						var imgParm = clacImgZoomParam(maxW,maxH,width,height);
						//初始化图片位置
						imgs.eq(n).css({"width":imgParm.width,"height":imgParm.height,"margin-left":imgParm.left,"margin-top":imgParm.top});
					}
				}
			}else{
				imgDom.onload = function(){
					width = imgDom.width;
					height = imgDom.height;
					//初始化图片显示的参数
					var imgParm = clacImgZoomParam(maxW,maxH,width,height);
					//初始化图片位置
					imgs.eq(n).css({"width":imgParm.width,"height":imgParm.height,"margin-left":imgParm.left,"margin-top":imgParm.top});
				}
			}
			imgDom.onerror = function(){
				width = 138;
				height = 138;
				//初始化图片显示的参数
				var imgParm = clacImgZoomParam(maxW,maxH,width,height);
				imgs.eq(n).css({"width":imgParm.width,"height":imgParm.height,"margin-left":imgParm.left,"margin-top":imgParm.top});
			}
			imgDom.src = src;
		}else{
			$(this).removeAttr("title");
		}
	});
};

/**
 * 图片转换成base64,不能转换本地图片
 */
function convertImgToBase64(url, callback, outputFormat){
  var canvas = document.createElement('CANVAS'),
    ctx = canvas.getContext('2d'),
    img = new Image;
  img.crossOrigin = 'Anonymous';
  img.onload = function(){
    canvas.height = img.height;
    canvas.width = img.width;
    ctx.drawImage(img,0,0);
    var dataURL = canvas.toDataURL(outputFormat || 'image/png');
    callback.call(this, dataURL);
    canvas = null; 
  };
  img.src = url;
}

/**
 * 验证邮箱地址格式
 * @param string str
 */
function isEmail(str){
	return /^(?:[a-zA-Z0-9]+[_\-\+\.]?)*[a-zA-Z0-9]+@(?:([a-zA-Z0-9]+[_\-]?)*[a-zA-Z0-9]+\.)+([a-zA-Z]{2,})+$/.test(str);
};
/**
 * 验证电话号码格式
 * @param string str
 */
function isTelNum(str){
	/*return /^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/.test(str);*/
	return /^(\d{3,4})-(\d{7,9})$/.test(str);
};
/**
 * 验证手机号码格式
 * @param string str
 */
function ismobileNum(str){
	return /^1[34578]\d{9}$/.test(str);
}
/**
 * 验证邮政编码格式
 * @param string str
 */
function ispostalcode(str){
	return /^\d{6}$/.test(str)
}
/**
 * 验证qq格式
 * @param string str
 */
function isQQ(str){
	return /^[1-9]\d{4,14}$/.test(str);
}

/**
 * 验证是否中英文数字的混合，不包含任何特殊字符
 * @param string str
 */
function isCED(str){
	return /^([0-9a-zA-Z]|[\u4E00-\u9FA5])*$/.test(str);
}

/**
 * 验证是否大于零的数字组合
 * @param string str
 */
function isPlusFloat(str){
	return /^\d*\.?\d*$/.test(str) && str - 0 > 0;
	return /^[+-]?\d*\.?\d*$/.test(str);
	//return /^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$/.test(str);
}

/** 正整数 **/
function positiveInteger(str){
	return /^[0-9]*[1-9][0-9]*$/.test(str)
}

/**
 * 验证是否英文数字的混合，不包含任何特殊字符
 * @param string str
 */
function isED(str){
	return /^([0-9a-zA-Z])*$/.test(str);
}

window.showPrevienJson = {};
window.rsimage = "";
function showPreview(dom){
	if($(".modal").length){
		$(".modal").remove();
	};
	//旋转按钮
	var buttons = "<button class='btn btn-info mr6 mb6' onclick='window.rsimage.rotateLeft();' title='逆时针旋转'>" +
		      	"		<i class='glyphicon glyphicon-repeat' style='transform:rotateX(180deg) rotateZ(180deg)'></i>" +
		      	"	</button>" +
		      	"<button class='btn btn-info mr6 mb6' onclick='window.rsimage.rotateRight();' title='顺时针旋转'>" +
		      	"	<i class='glyphicon glyphicon-repeat'></i>" +
		      	"</button>" +
		      	"<button class='btn btn-info mb6' onclick='window.rsimage.reset();' title='重置'>" +
		      	"	<i class='glyphicon glyphicon-refresh'></i>" +
		      	"</button>";
	var typeB = getBrowerType() ;
	if(typeB == "IE8" || typeB =="IE7" || typeB == "IE6"){
		buttons = "";
	}
	var modal = "<div class='modal fade'>"+
				"	<div class='modal-dialog modal-lg'>"+
				"   	<div class='modal-content'>"+
				"    		<div class='modal-header'>"+
				"     			<button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>"+
				"    			<h4 class='modal-title'>标题</h4>"+
				"			</div>"+
				" 		<div class='modal-body' >"+
				" 		</div>"+
				"		<div class='text-center'>" +buttons+
				"	</div>"+
				"</div>";
	$("body").append(modal);
	//设置模态框.modal-body的高度
	var modalH = $("iframe",window.top.document).eq(0).height() * 0.65 || $(window).height * 0.6;
	$(".modal-body").height(modalH);
	var obj = $(dom);
	var par = obj.parents(".prev_img_c");
	window.showPrevienJson.par = par;
	window.showPrevienJson.dom = dom;
	$(".modal").modal("show");
	
};

function showPrevImg(dom,par){
	//获取标题
	var title = par.find("h5").text() || "查看图片";
	//获取模态框的.modal-body的宽度
	var modalW = $(".modal-body").width(); 
	var modalH = $("iframe",window.top.document).eq(0).height() * 0.65 || $(window).height * 0.6;
	//获取图片的路径
	var wsrc = par.find(".prev_img_up img").attr("src");
	var imgId = par.find(".prev_img_up img").attr("id") || par.find(".prev_img_up div").attr("id");
	var imgDom = par.find(".prev_img_up img").get(0) || par.find(".prev_img_up div").get(0);
	
	//获取图片的真实大小
	getImgNaturalDimensions(imgDom,function(nWidth,nHeight){
		var rect = adapterImgSize(modalW,modalH,nWidth,nHeight);
		$(".modal-title").html(title);
		if(wsrc){
    		//$(".modal-body").html("<img src="+src+" width="+rect.width+" height="+rect.height+" style='margin-left:"+rect.left+"px;margin-top:"+rect.top+"px;'/>")
    		$(".modal-body").html("<div id='rsImg' style='width:"+modalW+"px;height:"+modalH+"px;overflow:auto;border:1px solid #ddd;'>"+
    								  "<img src="+wsrc+" width="+rect.width+" height="+rect.height+" style='margin-left:"+rect.left+"px;margin-top:"+rect.top+"px' />"+
    							  "</div>");
    		window.rsimage = new RSImage({
				"target":$("#rsImg"),
				"src":wsrc,
				"isPartZoom":true,
				"isScale":false
			});
    		//window.rsimage.partZoomOut();
		}else{
			var typeB = getBrowerType();
    		if(typeB == "IE8" || typeB == "IE9" ){//IE8 9使用滤镜
    			var src = $(dom).siblings("input[type='file']").val();
    			var sFilter='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
    			$(".modal-body").html("<div id='rsImg' style='width:"+modalW+"px;height:"+modalH+"px;overflow:auto;border:1px solid #ddd;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)'>"+
    					"<div style='width:"+rect.width+"px;height:"+rect.height+"px;margin-top:"+rect.top+"px;;margin-left:"+rect.left+"px;"+sFilter+src+"\"'></div>"+
					  "</div>"); 
    			window.rsimage = new RSImage({
    				"target":$("#rsImg"),
    				"src":src
    			});
    		}
		};
	});
}

$(document).on('shown.bs.modal',".modal", function (e) {
	//debugger;
	if(window.showPrevienJson.par && window.showPrevienJson.dom){
		showPrevImg(window.showPrevienJson.dom,window.showPrevienJson.par)
	}
});

//图片上传
function imgUpload(id){
	$("#"+id).trigger("click");
};

//图片验证
function checkImg(obj){
	//var _this = obj;
	imgValid(obj,{
		fileSize:"1M",
		callback:function(ok){
			if(ok){
				var parobj = $(obj).parents(".prev_img_c");
				var id1= parobj.find(".prev_img_up").attr("id");
				var id2 = parobj.find(".prev_img_up img").attr("id");
				previewImage(id1,id2,obj);
			}
		}
	});
};

//获取cookie  
function getCookieValue(cookieName){  
    var cookieValue = document.cookie;
    var cookieStartAt = cookieValue.indexOf(cookieName+"=");  
    if(cookieStartAt==-1){  
    	return null;
    }else{  
        cookieStartAt = cookieValue.indexOf("=",cookieStartAt)+1;  
        cookieEndAt = cookieValue.indexOf(";",cookieStartAt);  
        if(cookieEndAt==-1){  
            cookieEndAt = cookieValue.length;  
        }  
        cookieValue = unescape(cookieValue.substring(cookieStartAt,cookieEndAt));//解码latin-1
    }  
    return cookieValue;  
};
//设置cookie
function setCookie(cookieName,cookieValue,cookieExpires,cookiePath){
	cookieValue = escape(cookieValue);//编码latin-1
	if(cookieExpires == "" || cookieExpires == undefined){
		var nowDate = new Date();
		nowDate.setMonth(nowDate.getMonth()+6);
		cookieExpires = nowDate.toGMTString();
		cookieValue += ";expires="+cookieExpires;
	}
	if(!cookiePath){
		cookieValue +=";Path=/"+cookiePath;
	}
	document.cookie = cookieName+"="+cookieValue;
};
//获取地址栏中的参数
function getLocalParm(){
	var urlParm = location.search ;
	var request = {};
	if(urlParm.indexOf("?") != -1){
		var str = urlParm.substr(1);
		if(str.indexOf("&") != -1){
			var strs = str.split("&");
			for(var i=0,len=strs.length;i<len;i++){
				request[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
			};
		}else{
			request[str.split("=")[0]] = unescape(str.split("=")[1]);
		}
	};
	return request;
};
//获取x，y坐标，返回对象
/*
	window.onmousedown = function(e){
		var pos = getXY(e);
		alert(pos.x +"==="+pos.y)
	}
*/
function getXY(e){
	var ev = e || window.event ;
	var x = 0 ;
	var y = 0 ;
	if(ev.pageX){
		x = ev.pageX;
		y = ev.pageY;
	}else{
		var scrLeft = 0;
		var scrTop = 0;
		//ie678---
		if(document.documentElement){
			scrLeft = document.documentElement.scrollLeft;
			scrTop = document.documentElement.scrollTop;
		}else{
			//IE9+、谷歌、
			scrLeft = document.body.scrollLeft;
			scrTop = document.body.scrollTop;
		}
		x = ev.clientX + scrLeft
		y = ev.clientY + scrTop
	}
	return {x:x,y:y}
};

/*
 * 获取表单内容的最大长度
 * 中文字符占2位，字母、数字、标点占一位
 * @parm:jQuery对象或dom对象
 * 
 * */
function getMaxLength(str){
	if(str){
		var len = str.length;
		var realLength = 0;
		var charCode = "";
		for(var i = 0;i<len;i++){
			charCode = str.charCodeAt(i);
			if(charCode >=0 && charCode<=128){
				realLength += 1;
			}else{
				realLength += 2;
			}
		}
		return realLength;
	}else{
		return 0;
	}
};

//兼容火狐浏览器的刷新时出现重复提交数据的提示
/*
 * 如果有formDom,则需要清空查询条件刷新，否则不需要清空查询条件刷新
 * */
function windowReload(formDom){
	setTimeout(function(){
		if(formDom){//清空高级查询条件刷新
			self.window.location.href = $(formDom).attr("action");
		}else{//不清空高级查询条件属性
			window.setQueryCondition && setQueryCondition() || window.location.reload();
		}
	},100);
};


//重设伪类，使字体图标强制生效
/*!(function redrawFontFace() {
    if ($.support.leadingWhitespace) return;
    $(window).one("load", function() {
     //   console.log("onload!!!!!!!!!!!");
        $('html').addClass('fix-ie-font-face');
        setTimeout(function() {
            $('html').removeClass('fix-ie-font-face');
        }, 10);
    });
}());*/
;(function(){
	if ($.support.leadingWhitespace) return;
    $(window).one("load", function() {
        $('html').addClass('fix-ie-font-face');
        setTimeout(function() {
            $('html').removeClass('fix-ie-font-face');
        }, 10);
    });
})();
;(function(){
	if ($.support.leadingWhitespace) return;
    $(window).onload = function() {
     //   console.log("onload!!!!!!!!!!!");
        $('html').addClass('fix-ie-font-face');
        setTimeout(function() {
            $('html').removeClass('fix-ie-font-face');
        }, 10);
    };
})();
/*;(function(){
	if ($.support.leadingWhitespace) return;
	$("body i.glyphicon").css("visibility","hidden!important");
	setTimeout(function() {
        $('body i.glyphicon').css('visibility',"visible");
    }, 10);
})();*/


/*
 * 显示jquery对象或dom对象上的data-title的值。
 * 需要showtit_tips样式类，已在main.css中定义
 * 
 * jdom为jquery对象或dom对象
 * 
 * */
function showDataTit(jdom){
	if(!jdom){
		return;
	};
	$(jdom).on("mouseenter",function(e){
		var ev = e || window.event;
		stopPropa(ev);
		if(!$("body").find(".showtit_tips").length){
			$("body").append("<div class='showtit_tips'></div>");
		};
		var _top = getTop($(this).get(0));
		var _scrTop = $(this).scrollTop();
		var _left = getLeft($(this).get(0));
		var _thisW = $(this).outerWidth();
		var menu_tips = $(".showtit_tips");
		var text = $(this).data("title");
		menu_tips.css({
			"top":_top - _scrTop,
			"left":_left + _thisW + 8
		});
		if(text){
			menu_tips.text(text);
			menu_tips.stop(true,false).fadeIn();
		}
	}).on("mouseleave",function(){
		$("body .showtit_tips").stop(true,false).fadeOut();
	});
};


function showDataTitDtl(jdom){
	if(!jdom){
		return;
	};
	$(jdom).on("mouseenter",function(e){
		var ev = e || window.event;
		stopPropa(ev);
		if(!$("body").find(".showtitdtl_tips").length){
			$("body").append("<div class='showtitdtl_tips'></div>");
		};
		var _top = getTop($(this).get(0));
		var _scrTop = $(this).scrollTop() + $(".maxTable_body").scrollTop();
		var _left = getLeft($(this).get(0));
		var _thisW = $(this).outerWidth();
		var _thisH = $(this).outerHeight();
		var menu_tips = $(".showtitdtl_tips");
		var text = $(this).find(".factory_item").data("title");
		menu_tips.css({
			"top":_top - _scrTop + (_thisH / 2) - 12,
			"left":_left + _thisW + 8
		});
		if(text){
			menu_tips.text(text);
			menu_tips.stop(true,false).fadeIn();
		}
	}).on("mouseleave",function(){
		$("body .showtitdtl_tips").stop(true,false).fadeOut();
	});
};

function showTelPhone(jdom){
	if(!jdom){
		return;
	};
	$(jdom).on("mouseenter",function(e){
		var tdDom = $(this).parents("td");
		var ev = e || window.event;
		stopPropa(ev);
		if(!$("body").find(".showtitdtl_tips").length){
			$("body").append("<div class='showtitdtl_tips'></div>");
		};
		var _top = getTop(tdDom.get(0));
		var _scrTop = tdDom.scrollTop() ;
		var _left = getLeft(tdDom.get(0));
		var _thisW = tdDom.outerWidth();
		var _thisH = tdDom.outerHeight();
		var menu_tips = $(".showtitdtl_tips");
		var text = tdDom.data("title");
		menu_tips.css({
			"top":_top - _scrTop + (_thisH / 2) - 12,
			"left":_left + _thisW + 8
		});
		if(text){
			menu_tips.text(text);
			menu_tips.stop(true,false).fadeIn();
		}
	}).on("mouseleave",function(){
		$("body .showtitdtl_tips").stop(true,false).fadeOut();
	});
};

//刷新
function winRefresh(){
	window.location.reload();
}

/*
 * 
 orderRemind({
	url:'',  					//请求地址
	method: '',					//请求方式
	time:15000,					//请求时间间隔，默认15秒
	msg: '',					// 提示内容,默认为空，显示ajax返回的msg信息
	isTop: false,				// 是否在顶层窗口显示，默认false,
	order_remind: false,		// 是否开启语音提示
	callback: function(){		// 点击提示消息的回调函数
	}
})
 * 
 	依赖maxRemind.js文件
 * */
function orderRemind(options){
	if(!options){
		return;
	}
	var fn = function(){
		$.ajax({
			url: options.url,
			type: options.method == 'undefined' ? options.method : 'get',
			success: function(data){
				if( data.success ){
					var nocheck_orderCount = data.obj.nocheck_orderCount;
					var noaccept_orderMoney = data.obj.noaccept_orderMoney;
					var daifahuo = data.obj.daifahuo;
					var daituikuan = data.obj.daituikuan;
					var medicationOrder=data.obj.medicationOrder;
					var newMsg = '您当前还有<div style="margin-left:12px;">';
					newMsg += (nocheck_orderCount > 0 || noaccept_orderMoney > 0) ? '普通订单：<br />' : '';
					newMsg += nocheck_orderCount > 0 ? "<a onclick=\"exOpIframe(tabIndex,'orderController/getOrderList.do?flag=1','待确认订单');\">"+ nocheck_orderCount +"个待确认订单</a>" : '';
					newMsg += nocheck_orderCount > 0 && noaccept_orderMoney > 0 ? ',' : '';
					newMsg += noaccept_orderMoney > 0 ? "<a onclick=\"exOpIframe(tabIndex,'orderController/getOrderList.do?flag=2','待收款订单');\">"+ noaccept_orderMoney +"个待收款订单</a>" : '';
					newMsg += (daifahuo > 0 || daituikuan > 0) ? '<br />智慧医院：<br />' : '';
					newMsg += daifahuo > 0 ? "<a onclick=\"exOpIframe(tabIndex,'hospitalController/orderList_all.do?flag=1','待发货订单');\">"+ daifahuo +"个待发货订单</a>" : '';
					newMsg += daifahuo > 0 && daituikuan > 0 ? ',' : '';
					newMsg += daituikuan > 0 ? "<a onclick=\"exOpIframe(tabIndex,'hospitalController/orderList_all.do?flag=2','待退款订单');\">"+ daituikuan +"个待退款订单</a>" : '';
					newMsg += (medicationOrder > 0) ? '<br />配药订单：<br />' : '';
					newMsg += medicationOrder > 0 ? "<a onclick=\"exOpIframe(tabIndex,'visitsRecordController/medicationOrder2.do','待配药订单');\">"+ medicationOrder +"个待配药订单</a>" : '';
					newMsg += '</div>需要处理，请注意查看!';
					new MaxRemind({
						isTop:options.isTop == 'undefined' ? options.isTop : false,					//提示框的显示的位置，false:在当前调用插件的窗口显示；true:在当前调用插件的顶层窗口显示。
						// msg: options.msg == 'undefined' ? options.msg : data.msg,
						msg: newMsg,
						order_remind: options.order_remind == 'undefined' ? false : options.order_remind,
						callback: function(obj){
							// console.log(tabIndex)
							options.callback && options.callback(obj)
						}
					});
				}
			}
		});
	};
	fn();
	setInterval(function(){
		fn();
	}, options.time || 15000)
}

// 表格tr点击拓展
;(function(win, $){
	var TableTrExpand = function(options){
		this.config = $.extend(true, {}, TableTrExpand.DEFAULTS, options);
		this._events();
		return this;
	}
	
	TableTrExpand.DEFAULTS = {
		id: '',
		expandTrClass: 'tr-panel',
		colspan: 30,
		loadUrl: '',
		attrArr: ['a','b'],
		eventsWidthSynFuc: null,
		callback: null
	}
	
	TableTrExpand.prototype = {
		_events: function(){
			var _this_ = this;
			var id = _this_.config.id;
			var expandTrClass = _this_.config.expandTrClass;
			var colspan = _this_.config.colspan;
			var loadUrl = _this_.config.loadUrl;
			// var data = '';
			var callback = _this_.config.callback;
			$(document).off('click.expand', "#"+ id +">tbody>tr:not('."+ expandTrClass +"')");
			$(document).on('click.expand', "#"+ id +">tbody>tr:not('."+ expandTrClass +"')", function(){
				var _this = $(this);
				if(_this.find('td').length <= 1){
					return;
				}
	  			var nextDom = _this.next();
	  			if(nextDom.hasClass(expandTrClass)){
	  				nextDom.siblings('tr.' + expandTrClass).remove();
	  				if(nextDom.get(0).style.display == 'none'){
	  					nextDom.show();
	  				}else{
	  					nextDom.hide()
	  				}
	  			}else{
	  				_this.siblings('tr.' + expandTrClass).remove()
	  				var trDom = $("<tr class='"+ expandTrClass +"'><td colspan='"+ colspan +"'></td></tr>");
	  				$(this).after(trDom);
	  				var data = _this_._getDataParm(_this);
	  				trDom.find('td').load(loadUrl, data, callback);
	  			}
	  			_this_.config.eventsWidthSynFuc && _this_.config.eventsWidthSynFuc(); 
	  		});
		},
		_getDataParm: function(jdom){
			if(this.config.attrArr.length){
				var parm = {};
				this.config.attrArr.forEach(function(item, index){
					parm[item] = $(jdom).attr(item);
				});
				return parm;
			}else{
				return '';
			}
		}
	}
	
	win.TableTrExpand = TableTrExpand;
})(window, jQuery);